<?php
	/**
	 * html elements generator for the application.
	 *
	 * powerful instrument for creating multi-functional html elements
	 * NOTE: for multi level lists use 'parent_id' field to identify the id of the parent element.
	 * @package Helpers
	 * @author Perkin Anton
	 * @version 2.1
	 */
	class HtmlxHelper extends HtmlHelper
	{
		/**
		 * CSS class for the informational table (is displayed at the bottom of the page and consists some supplemental info)
		 */
		public $informationalTableCssClass = 'information';
		
		/**
		 * CSS class for the informational table cell
		 */
		public $informationalTableCellCssClass = 'informationTableText';
		
		/**
		 * CSS class for the mass operations table
		 */
		public $massOperationsTableCssClass = 'massOperation';

		/**
		 * CSS class for the mass operations table
		 */
		public $massOperationsHeaderCellCssClass = 'massHeader';
		
		/**
		 * CSS class for the grid cell
		 */
		public $gridCellCssClass = 'gridCell';

		/**
		 * CSS class for the odd grid row
		 */
		public $gridRowOddCssClass = 'gridRow';
		
		/**
		 * CSS class for the even grid row
		 */
		public $gridRowEvenCssClass = 'gridRow';

		/**
		 * CSS class for the input text field
		 */
		public $inputTextCssClass = 'text';

		/**
		 * CSS class for the input search field (used in fast search feature)
		 */
		public $inputTextSearchCssClass = 'search';

		/**
		 * CSS class for the input file field
		 */
		public $inputFileCssClass = 'file';
		
		/**
		 * CSS class for the checkbox field
		 */
		public $checkboxCssClass = 'checkbox';

		/**
		 * CSS class for the combobox 
		 */
		public $comboboxCssClass = 'combobox';

		/**
		 * submit button name 
		 */
		public $submitButtonName = 'submit';
		
		/**
		 * CSS class for the error (span)  
		 */
		public $errorSpanCssClass = 'error';

		/**
		 * CSS class for the error (td)  
		 */
		public $errorCellCssClass = 'error';
		
		/**
		 * CSS class for table header row   
		 */
		public $tableHeaderRowCssClass = 'header';
		
		/**
		 * CSS class for table header cell   
		 */
		public $tableHeaderCellCssClass = 'header';
		
		/**
		 * CSS class for MenuText table   
		 */
		public $menuTextTableCssClass = 'menutext1';
		
		/**
		 * CSS class for MenuText table   
		 */
		public $menuTextCellCssClass = 'menutext1';
		
		/**
		 * CSS class for the label cells   
		 */
		public $labelCellCssClass = 'label';
		
		/**
		 * CSS class for the label cells   
		 */
		public $commentSpanCssClass = 'comment';
		
		/**
		 * CSS class for the submit table   
		 */
		public $submitTableCssClass = 'submitTable';
		
		/**
		 * CSS class for the submit table cell   
		 */
		public $submitCellCssClass = 'submitTable';
		
		/**
		 * CSS class for the cancel button
		 */
		public $cancelButtonCssClass = 'cancel';
		
		/**
		 * CSS class for the cancel button
		 */
		public $submitButtonCssClass = 'submit';
		
		/**
		 * CSS class for the cancel button
		 */
		public $confirmDeleteTableCssClass = 'login';
		
		/**
		 * CSS class for the cancel button
		 */
		public $inputLogCommentCssClass = 'log_comment';
		
		/**
		 * CSS class for the additional fields table
		 */
		public $additionalFieldsTableCssClass = 'eva';
		
		/**
		 * CSS class for the status bar table
		 */
		public $statusBarTableCssClass = 'status_bar';
		
		/**
		 * CSS class for the true (first) status bar table cell 
		 */
		public $statusBarTrueCellCssClass = 'status_bar_true';
		
		/**
		 * CSS class for the false (second) status bar table cell 
		 */
		public $statusBarFalseCellCssClass = 'status_bar_false';
		
		
		# SITE HELPERS #

		/**
		 * Generates section header
		 * @param $text title
		 */
		public static function SectionHeader($text)
		{
            echo "<h3 style = 'border-bottom: 1px solid #CCCCCC; margin-bottom: 5px; '>$text</h3>";
		}

	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputTextRowSite($label, $input_name, $input_value, $input_html_attributes = NULL, $comment = NULL, $model = NULL)
		{
			global $current_controller, $object;

            //gets the appropriate model
			$current_controller->controller_model = (empty($model)) ? $current_controller->controller_model : $current_controller->GetModelObject($model);

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//align depending on data type
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
				$align="style='text-align:right; padding-right:3px'";
			else $align = "";

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//sets default value
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//validation errors
			$input_error = (empty($model)) ? $current_controller->controller_model->validation_errors[$input_name] : $_SESSION['validations_errors'][$model][$input_name];
			$id_span = str_replace('_','',$input_name);

			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = 0;

			//checks if min/max length JS validaion is needed
			$validate_min_max_length = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_length]))
			{
				$min_length = $current_controller->controller_model->db_structure[$input_name][min_length];
				$validate_min_max_length = 1;
			}
			else $min_length = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][length]))
			{
				$max_length = $current_controller->controller_model->db_structure[$input_name][length];
				$validate_min_max_length = 1;
			}
			else $max_length = 0;

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//checks if email JS validaion is needed
			$validate_email = 0;
			if ($current_controller->controller_model->db_structure[$input_name]['sub_type'] == 'email')
			{
				$validate_email = 1;
			}

			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_min_max_length)||($validate_regexp)||($validate_email))
			{
				if ($validate_email) $js_validation .= "ValidateEmail(this, \"".LANG_NOT_VALID_EMAIL."\"); ";
				if ($validate_min_max_length) $js_validation .= "ValidateMinMaxLength(this, $min_length, $max_length); ";
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onblur = '$js_validation'";
			}

			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal')
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//max length
			$maxlen = $current_controller->controller_model->db_structure[$input_name]['length'];

			//generates html
			$item_class = (empty($input_error)) ? '' : 'error';
			echo "
    			<li class = '$item_class'>
    				<label for='$input_name'>".ucfirst($label).$required."</label>";

                    $this->InputText($input_name, $input_value, $input_html_attributes." id = '$input_name' class = 'text' maxlength = '$maxlen' "." ".$align." ".$js_validation.$validate_type);
			        echo " <span class = 'comment'>".$comment."</span>";

            echo "
                    <div class='vError {$input_name}_error' id = '{$input_name}_error'>$input_error</div>
    			</li>";

			$this->InputErrorHandler($input_name, $input_error);
		}

		    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputTextRowSite3($label, $input_name, $input_value, $input_html_attributes = NULL, $comment = NULL, $model = NULL)
		{
			global $current_controller, $object;

            //gets the appropriate model
			$current_controller->controller_model = (empty($model)) ? $current_controller->controller_model : $current_controller->GetModelObject($model);

			//align depending on data type
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
				$align="style='text-align:right; padding-right:3px'";
			else $align = "";

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "<span class='asterisk'>*</span> ";
			else
				 $required = "";

			//sets default value
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//validation errors
			$input_error = (empty($model)) ? $current_controller->controller_model->validation_errors[$input_name] : $_SESSION['validations_errors'][$model][$input_name];
			$id_span = str_replace('_','',$input_name);

			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = 0;

			//checks if min/max length JS validaion is needed
			$validate_min_max_length = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_length]))
			{
				$min_length = $current_controller->controller_model->db_structure[$input_name][min_length];
				$validate_min_max_length = 1;
			}
			else $min_length = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][length]))
			{
				$max_length = $current_controller->controller_model->db_structure[$input_name][length];
				$validate_min_max_length = 1;
			}
			else $max_length = 0;

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//checks if email JS validaion is needed
			$validate_email = 0;
			if ($current_controller->controller_model->db_structure[$input_name]['sub_type'] == 'email')
			{
				$validate_email = 1;
			}

			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_min_max_length)||($validate_regexp)||($validate_email))
			{
				if ($validate_email) $js_validation .= "ValidateEmail(this, \"".LANG_NOT_VALID_EMAIL."\"); ";
				if ($validate_min_max_length) $js_validation .= "ValidateMinMaxLength(this, $min_length, $max_length); ";
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onblur = '$js_validation'";
			}

			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal')
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//max length
			$maxlen = $current_controller->controller_model->db_structure[$input_name]['length'];

			//generates html
			$item_class = (empty($input_error)) ? '' : 'onError';
			echo "
				<div class='fld_wrap' style = '' >
					<label for='$input_name' class='fld_label'>".$required.ucfirst($label)." <span>$comment</span></label>";
                    $this->InputText($input_name, $input_value, $input_html_attributes." id = '$input_name' class = 'fldtext $item_class' maxlength = '$maxlen' "." ".$align." ".$js_validation.$validate_type);
			echo "	<p class='flderror {$input_name}_error' id = '{$input_name}_error'>$input_error</p>
				</div>			
			";

			$this->InputErrorHandler($input_name, $input_error);
		}		
		
	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputPasswordRowSite($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//align depending on data type
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
				$align="style='text-align:right; padding-right:3px'";
			else $align = "";

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//sets default value
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);

			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = 0;

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//checks if min/max length JS validaion is needed
			$validate_min_max_length = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_length]))
			{
				$min_length = $current_controller->controller_model->db_structure[$input_name][min_length];
				$validate_min_max_length = 1;
			}
			else $min_length = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][length]))
			{
				$max_length = $current_controller->controller_model->db_structure[$input_name][length];
				$validate_min_max_length = 1;
			}
			else $max_length = 0;

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_min_max_length)||($validate_regexp))
			{
				if ($validate_min_max_length) $js_validation .= "ValidateMinMaxLength(this, $min_length, $max_length); ";
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onblur = '$js_validation'";
			}

			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal')
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//generates html
			$item_class = (empty($input_error)) ? '' : 'error';
			echo "
    			<li class = '$item_class'>
    				<label for='$input_name'>".ucfirst($label).$required."</label>";

                    $this->Password($input_name, $input_value, $input_html_attributes." id = '$input_name' class = 'text' maxlength = '16' autocomplete='off' "." ".$align." ".$js_validation.$validate_type);

            echo "
                    <div class='vError {$input_name}_error' id = '{$input_name}_error'>$input_error</div>
    			</li>";

			$this->InputErrorHandler($input_name, $input_error);
		}

	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputPasswordRowSite3($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{
			global $current_controller, $object;

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//sets default value
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);

			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = 0;

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//checks if min/max length JS validaion is needed
			$validate_min_max_length = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_length]))
			{
				$min_length = $current_controller->controller_model->db_structure[$input_name][min_length];
				$validate_min_max_length = 1;
			}
			else $min_length = 0;

			if (isset($current_controller->controller_model->db_structure[$input_name][length]))
			{
				$max_length = $current_controller->controller_model->db_structure[$input_name][length];
				$validate_min_max_length = 1;
			}
			else $max_length = 0;

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_min_max_length)||($validate_regexp))
			{
				if ($validate_min_max_length) $js_validation .= "ValidateMinMaxLength(this, $min_length, $max_length); ";
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onblur = '$js_validation'";
			}

			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal')
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//generates html
			$item_class = (empty($input_error)) ? '' : 'onError';
			echo "
				<div class='fld_wrap' style = 'padding-top: 6px; ' >
					<label for='$input_name' class='fld_label'>".ucfirst($label).$required."</label>";
			        $this->Password($input_name, $input_value, $input_html_attributes." id = '$input_name' class = 'fldtext $item_class' maxlength = '16' autocomplete='off' "." ".$align." ".$js_validation.$validate_type);
			echo "	<p class='flderror {$input_name}_error' id = '{$input_name}_error'>$input_error</p>
				</div>			
			";

			$this->InputErrorHandler($input_name, $input_error);
		}
		
	    /**
		 * Generates table row with the input data field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputDateRowSite($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $editable = true)
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//loads 'by default' value from the model
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);

			$input_value_initial = $input_value;

			if (!empty($input_value))
			{
				$temp = split(' ', $input_value);

				//date parts separator
				$date_parts_separator = (substr_count($temp[0], '-', 0, strlen($temp[0])) > 0 ) ? '-' : '.';

				$input_value_array = explode($date_parts_separator, $temp[0]);

				//swaps year and day if necessary
				if (strlen($input_value_array[0]) == 4)
				{
					$temp_swap = $input_value_array[0];
					$input_value_array[0] = $input_value_array[2];
					$input_value_array[2] = $temp_swap;
				}

				$input_value = implode($date_parts_separator, $input_value_array);

				$time_value_array = $temp[1];
			}
			else
			{
				$input_value = '';
				$time_value_array = '';
				$temp = '';
			}

			//translates months' array
			foreach (Arrays::$months as &$month)
			{
				eval("\$temp = {$month[name]};");
				$month[name] = $temp;
			}

			//generates html
			echo "
                        <tr>
                        	<td class='bold_utl'>".ucfirst($label).$required.":";

			if (!empty($input_error))
				echo "<br /><span style='font-size: 10px; color: red; '>$input_error</span>";

            echo "          </td><td colspan='2'>";
								$this->InputText($input_name, $input_value_initial, 'id = "'.$input_name.'" class="inpted_util2"'." ".$align." ".$input_html_attributes.$js_validation.$validate_type);
            echo "
                            </td>
                        </tr>
			";
		}

	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputTextBlockSite($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $editable = true)
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//align depending on data type
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
				$align="style='text-align:right; padding-right:3px'";
			else $align = "";

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//sets default value
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);

			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = '-';

			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = '-';

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_regexp))
			{
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onChange = '$js_validation'";
			}

			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal')
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//generates html
			if ($editable)
			{
				echo "<div class='briefInfoArive2'>
			          	<label style='width:44%'>".ucfirst($label)."</label>
			            <span>";

				$this->InputText($input_name, $input_value, "id = '$input_name' style='width: 60px' onfocus='if(this.className == \"\") this.className = \"active\";' onblur='if(this.className==\"active\") this.className=\"\";'"." ".$align." ".$input_html_attributes.$js_validation.$validate_type);

				echo "  </span></div>";
			}
			else
			{
				echo "<div class='briefInfoArive'><span>".ucfirst($label).":</span>";
				echo "<strong>$input_value</strong></div>";

				$this->hidden($input_name, $input_value);
			}

			$this->InputErrorHandler($input_name, $input_error);
		}

	    /**
		 * Generates table row with the checkbox input field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input field name
		 * @param boolean $is_checked indicates whether the element should be checked
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $tr_html_attributes html attributes for the tr tag
		 * @param string $input_value checkbox value
	    */
		public function CheckboxRowSite($label, $input_name, $is_checked, $input_html_attributes=null, $input_value=1, $editable = true)
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];

			//generates html
			echo "
    			<li id='remember_me' style = ''>";

    				echo "<label for='$input_name' style = 'white-space: nowrap; line-height: 1.4; ' id = 'checkbox_label'> ".ucfirst($label)."</label>";
					$this->hidden($input_name, '');
			        $this->Checkbox($input_name, $input_value, $is_checked, "class = 'checkbox' $input_html_attributes autocomplete='off' ");

    		echo "</li>";
		}

		    /**
		 * Generates table row with the checkbox input field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input field name
		 * @param boolean $is_checked indicates whether the element should be checked
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $tr_html_attributes html attributes for the tr tag
		 * @param string $input_value checkbox value
	    */
		public function CheckboxRowSite3($label, $input_name, $is_checked, $input_html_attributes=null, $input_value=1, $editable = true)
		{
			global $current_controller, $object;

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];

			//generates html
			echo "
				<div class='fld_wrap remember-me clear'>";
					XHTML::InputHidden($input_name, '');
			        $this->Checkbox($input_name, $input_value, $is_checked, "id = '$input_name' class = 'checkbox' $input_html_attributes autocomplete='off' ");
			echo "	<label for='$input_name' class='fld_label' style = ''>".ucfirst($label)."</label>
				</div>			
			";
		}		
		
		/**
		 * Generates checkbox group row for this project style
		 *
		 * @param string $label label
		 * @param string $input_name field name
		 * @param array $value_array array with all possible options
		 * @param array $selected_array array with selected options
		 */
		public function CheckBoxGroupRowSite($label, $input_name, array $value_array, $selected_array = array())
		{
			//header label
			if (!empty($label))
			{
    			echo ucfirst($label).'<br />';
			}

			//list
			foreach ($value_array as $item)
			{
				$id = array_shift($item);
				$text = array_shift($item);

				$checked = '';
				if (!empty($selected_array))
				{
					foreach ($selected_array as $k => $v)
					{
						if ($k == $id) $checked = "checked = 'checked'";
					}
				}

				//checkbox & label
				echo "<nobr id='nobr_{$input_name}_{$id}'>";
				$this->CheckBox($input_name."[$id]", 1, $checked, "style = 'margin: 0px; padding: 0px; ' id = '{$input_name}_{$id}'");
				echo "&nbsp;".$text."&nbsp;&nbsp;&nbsp;</nobr>";
				echo "<br id='br_{$input_name}_{$id}' />";
			}

		}

		/**
		 * Generates checkbox group row for this project style
		 *
		 * @param string $label label
		 * @param string $input_name field name
		 * @param array $value_array array with all possible options
		 * @param array $selected_array array with selected options
		 */
		public function CheckBoxGroupRowSite3($label, $input_name, array $value_array, $selected_array = array())
		{
			//header label
			if (!empty($label))
			{
    			echo ucfirst($label).'<br />';
			}

			//list
			foreach ($value_array as $item)
			{
				$id = array_shift($item);
				$text = array_shift($item);

				$checked = '';
				if (!empty($selected_array))
				{
					foreach ($selected_array as $k => $v)
					{
						if ($k == $id) $checked = "checked = 'checked'";
					}
				}

				//generates html
				echo "	<div class='fld_wrap remember-me clear' id='nobr_{$input_name}_{$id}'>";
				        	$this->Checkbox($input_name."[$id]", 1, $checked, "id = '{$input_name}_{$id}' class = 'checkbox' $input_html_attributes autocomplete='off' ");
				echo "		<label for='$input_name' class='fld_label' style = 'display: inline; '>".ucfirst($text)."</label>
					  	</div>";
			}

		}		
		
	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputFileRowSite($label, $input_name, $filename, $folder, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);

			//generates html
			$item_class = (empty($input_error)) ? '' : 'error';
			echo "
    			<li class = '$item_class'>
    				<label for='$input_name'>".ucfirst($label).$required."</label>";

        			$this->InputFile($input_name, $input_value, 'class="'.$this->inputFileCssClass.'"'." ".$align." ".$input_html_attributes);
        			$this->hidden('MAX_FILE_SIZE', $_SESSION[system_settings][file_max_upload_size]);

					//uploaded file
        			if (is_file($_SERVER['DOCUMENT_ROOT']."/app/upload/$folder/$filename"))
        			{
        			    echo "<div style = 'margin-left: 126px; ' id = '{$input_name}_box'>";

            			    //actions
                			echo "<div style = ''><br />";
                			    XHTML::Anchor("/app/upload/$folder/$filename", "<img src = '".IMAGES."attach.gif' width = '14' height = '14' />&nbsp;".Language::Get('Download'), array('class' => 'success'));
                                echo "&nbsp;&nbsp;";
                			    XHTML::Anchor(false, "<img src = '".IMAGES."btnDelete.gif' />&nbsp;".Language::Get('Delete', 'CAPITALIZE'), array('class' => 'delete', "onclick" => 'if (confirm("Do you really want to delete this image?")) {SendValues("/'.$current_controller->name.'/DeleteFile/'.str_replace('_', '+', $filename).'/'.str_replace('_', '+', $input_name).'?folder='.$folder.'"); ID("'.$input_name.'_box").style.display = "none";} return false; '));
                		    echo "</div>";

            			echo "</div>";
        			}
        			else
        			{
        			    echo "<div class='vError' id = '{$name}_error'>$input_error</div>";
        			}

            echo "</li>";
		}

		/**
		 * Generates table row with the checkbox input field
		 * @param $label
		 * @param $name
		 * @param $folder
		 * @param $filename
		 * @param $error
		 * @param $html_attributes
		 */
		public function InputImageRowSite($label, $name, $folder, $filename, $error = '', $html_attributes = '')
		{
		    global $current_controller;

			$item_class = (empty($input_error)) ? '' : 'error';
			echo "
    			<li class = '$item_class'>
    				<label for='$input_name'>".ucfirst($label).$required."</label>";

        			$this->InputFile($name, '', 'class="'.$this->inputFileCssClass.'"'." ".$align." ".$input_html_attributes);
        			$this->hidden('MAX_FILE_SIZE', $_SESSION[system_settings][file_max_upload_size]);

			//uploaded file
			if (is_file($_SERVER['DOCUMENT_ROOT']."/app/upload/$folder/$filename"))
			{
			    echo "<div style = 'margin-left: 126px; ' id = '{$name}_box'>";
			    echo "<table><tr><td>";

			        //image thumb
    			    XHTML::Img("/app/upload/$folder/thumbs/$filename", Language::Get('Profile photo'), array('onclick' => '$("#'.$name.'_popup").dialog("open"); ', 'id' => $name.'_image', 'style' => 'cursor: pointer; '));

    			    //image popup
    			    jQuery::Dialog($name.'_popup', array('autoOpen' => 'false', 'title' => "'".Language::Get('Profile photo')."'"));
    			    echo "<div id = '{$name}_popup' style = 'text-align: center; '>";
    			        XHTML::Img("/app/upload/$folder/$filename", Language::Get('Profile photo'));
    			    echo "</div>";

    			echo "</td><td valign = 'top'>";

    			    //actions
        			echo "<div style = 'white-space: nowrap; '>";
        			    XHTML::Anchor(false, "<img src = '".IMAGES."btnDelete.gif' />&nbsp;".Language::Get('Delete', 'CAPITALIZE'), array('class' => 'delete', "onclick" => 'if (confirm("Do you really want to delete this image?")) {SendValues("/'.$current_controller->name.'/DeleteFile/'.$filename.'/'.str_replace('_', '+', $name).'?folder='.$folder.'"); ID("'.$name.'_box").style.display = "none";} return false; '));
        			    echo '<br />';
        			    XHTML::Anchor(false, "<img src = '".IMAGES."help.gif' width = '14' height = '14' />&nbsp;".Language::Get('See full size'), array('class' => 'success', 'onclick' => '$("#'.$name.'_popup").dialog("open"); '));
        			echo "</div>";

        		echo "</td></tr></table>";

    			echo "</div>";
			}
			else
			{
			    echo "<div class='vError' id = '{$name}_error'>$input_error</div>";
			}

            echo "</li>";

			echo "
				<input type='hidden' name='MAX_FILE_SIZE' value='<?php echo $error; ?>'>
				<input type='hidden' name='time_id' value='<?php echo time(); ?>'>
				<input type='hidden' name='replace' value='y'>";
		}		
		
		/**
		 * Generates dummy text block
		 * @param string $text
		 */
		public static function DummyTextBlock($text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
		{
            echo "
            	<p>
            		$text
            	</p>
            ";
		}

		/**
		 * Generates submit button row
		 * @param unknown_type $input_name
		 * @param unknown_type $input_value
		 */
		public function InputSubmitRowSite($input_name, $input_value, $html_attributes = '')
		{
		    echo "<li id='log_in'>";
		        $this->submit($input_name, $input_value, "$html_attributes class = 'submit'");
    	    echo "</li>";
		}

		/**
		 * Generates submit button row
		 * 
		 * @param string $input_name
		 * @param string $input_value
		 * @param string $html_attributes
		 */
		public function InputSubmitRowSite3($input_name, $input_value, $html_attributes = '')
		{
			echo "<div class='prof-btn clear'>";
					$this->submit($input_name, $input_value, "$html_attributes class = 'edit-box'");
			echo "</div>";
		}
		
	    /**
		 * Generates table row with the selectbox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		*/
		public function ComboBoxRowSite($label, $combo_name, $value_array = array(), $selected, $input_html_attributes=null, $editable = true)
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($combo_name, $selected, &$input_html_attributes)) return;
			}

			if (isset($value_array[0][parent_id])) $value_array = $this->GetMultiLevelList($value_array);

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$combo_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];

			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}

			//checks whetther to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE)
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}

			//generates html
			$item_class = (empty($input_error)) ? '' : 'error';
			echo "
    			<li class = '$item_class'>
    				<label for='$combo_name'>".ucfirst($label).$required."</label>";

                    $this->combo($combo_name, $value_array, $selected, "$input_html_attributes class='text'");

            echo "
                    <div class='vError' id = '{$combo_name}_error'>$input_error</div>
    			</li>";

			//for logs
			$pos = strpos($combo_name, '[');
			if ($pos)
			$combo_name = substr($combo_name, 0, $pos).'_text'.substr($combo_name, $pos);
			else
			$combo_name = $combo_name.'_text';
			$this->hidden($combo_name, '');

			$this->InputErrorHandler($combo_name, $input_error);
		}

	    /**
		 * Generates table row with the selectbox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		*/
		public function ComboBoxRowSite3($label, $combo_name, $value_array = array(), $selected, $input_html_attributes=null, $block_class = 'fld_wrap')
		{
			global $current_controller, $object;

			if (isset($value_array[0][parent_id])) $value_array = $this->GetMultiLevelList($value_array);

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$combo_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "<span class='asterisk'>*</span> ";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];

			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}

			//checks whetther to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE)
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}

			//generates html
			$item_class = (empty($input_error)) ? '' : 'onError';
			echo "
				<div class='$block_class' style = '' >
					<label for='$combo_name' class='fld_label'>".$required.ucfirst($label)."</label>";
                    $this->Combo($combo_name, $value_array, $selected, "$input_html_attributes class='fldselect'");
					echo "	<p class='flderror {$combo_name}_error' id = '{$combo_name}_error'>$input_error</p>
				</div>			
			";

			$this->InputErrorHandler($combo_name, $input_error);
		}
		
	    /**
		 * Generates table row with the selectbox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		*/
		public function SelectBoxRowSite($label, $combo_name, $value_array = array(), $selected, $input_html_attributes=null, $editable = true)
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($combo_name, $selected, &$input_html_attributes)) return;
			}

			if (isset($value_array[0][parent_id])) $value_array = $this->GetMultiLevelList($value_array);

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$combo_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];

			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}

			//checks whetther to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE)
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}

			//generates html
			$item_class = (empty($input_error)) ? '' : 'error';
			echo "
    			<li class = '$item_class'>
    				<label for='$combo_name'>".ucfirst($label).$required."</label>";

                    $this->select($combo_name, $value_array, $selected, "$input_html_attributes class='text'");

            echo "
                    <div class='vError' id = '{$combo_name}_error'>$input_error</div>
    			</li>";

			//for logs
			$pos = strpos($combo_name, '[');
			if ($pos)
			$combo_name = substr($combo_name, 0, $pos).'_text'.substr($combo_name, $pos);
			else
			$combo_name = $combo_name.'_text';
			$this->hidden($combo_name, '');

			$this->InputErrorHandler($combo_name, $input_error);
		}

	    /**
		 * Generates table row with the selectbox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		*/
		public function SelectBoxRowSite3($label, $combo_name, $value_array = array(), $selected, $input_html_attributes=null, $block_class = 'fld_wrap')
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($combo_name, $selected, &$input_html_attributes)) return;
			}

			if (isset($value_array[0][parent_id])) $value_array = $this->GetMultiLevelList($value_array);

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$combo_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];

			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}

			//checks whetther to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE)
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}

			//generates html
			$item_class = (empty($input_error)) ? '' : 'onError';
			echo "
				<div class='$block_class' style = '' >
					<label for='$combo_name' class='fld_label'>".ucfirst($label).$required."</label>";
					$this->Select($combo_name, $value_array, $selected, "$input_html_attributes class='fldselect'");
					echo "	<p class='flderror {$combo_name}_error' id = '{$combo_name}_error'>$input_error</p>
				</div>			
			";

			$this->InputErrorHandler($combo_name, $input_error);
		}
		
	    /**
		 * Generates table row with the textarea
		 *
		 * @param string $label label for the row
		 * @param string $textarea_name textarea name
		 * @param text $textarea_value textarea value
		 * @param string $input_html_attributes html_attributes for the textarea field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
  		 * @param boolean $is_rich_textarea defines whether to use wysiwyg editor or not
		*/
		public function TextareaRowSite($label, $textarea_name, $textarea_value, $input_html_attributes=null, $comment=null, $editable = true)
		{
			global $current_controller, $object;

			//if $is_rich_textarea is not specified, finds its value in the config variable
			if (!isset($is_rich_textarea))
			{
				if ($object->config->use_rta == 'true') $is_rich_textarea = 1;
				else $is_rich_textarea = 0;
			}

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($textarea_name, $input_html_attributes)) return;
			}

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$textarea_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			$input_error = $current_controller->controller_model->validation_errors[$textarea_name];
			$id_span = str_replace('_','', $textarea_name);

			//generates html
			echo "
    			<li class = '$item_class'>
    				<label for='$textarea_name'>".ucfirst($label).$required."</label>";

						$this->Textarea($textarea_name, $textarea_value, $input_html_attributes, $is_rich_textarea);
            
			echo "		<span class = 'comment'>$comment<span>
                    <div class='vError' id = '{$combo_name}_error'>$input_error</div>
    			</li>";
						
			$this->InputErrorHandler($textarea_name, $input_error);
		}

	    /**
		 * Generates table row with the textarea
		 *
		 * @param string $label label for the row
		 * @param string $textarea_name textarea name
		 * @param text $textarea_value textarea value
		 * @param string $input_html_attributes html_attributes for the textarea field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
  		 * @param boolean $is_rich_textarea defines whether to use wysiwyg editor or not
		*/
		public function TextareaRowSite3($label, $textarea_name, $textarea_value, $input_html_attributes=null, $comment=null, $editable = true)
		{
			global $current_controller, $object;

			//if $is_rich_textarea is not specified, finds its value in the config variable
			if (!isset($is_rich_textarea))
			{
				if ($object->config->use_rta == 'true') $is_rich_textarea = 1;
				else $is_rich_textarea = 0;
			}

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($textarea_name, $input_html_attributes)) return;
			}

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$textarea_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			$input_error = $current_controller->controller_model->validation_errors[$textarea_name];
			$id_span = str_replace('_','', $textarea_name);

			//generates html
			echo "
				<div class='fld_wrap' style = '' >
					<label for='$textarea_name' class='fld_label'>".ucfirst($label).$required." <span>$comment</span></label>";
                    $this->Textarea($textarea_name, $textarea_value, $input_html_attributes." class = 'fldarea'", $is_rich_textarea);
			echo "	<p class='flderror {$textarea_name}_error' id = '{$textarea_name}_error'>$input_error</p>
				</div>			
			";
						
			$this->InputErrorHandler($textarea_name, $input_error);
		}
		
	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/
		public function InputPhoneRowSite($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $editable = true)
		{
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;
			}

			//align depending on data type
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
				$align="style='text-align:right; padding-right:3px'";
			else $align = "";

			//check whether to print '*' or not
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE))
			     $required = "*";
			else
				 $required = "";

			//sets default value
			if (isset($current_controller->controller_model->db_structure[$input_name][by_default])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name][by_default];

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);

			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = '-';

			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = '-';

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}

			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_regexp))
			{
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onChange = '$js_validation'";
			}

			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal')
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//check for int
			$validate_type = " onkeyup = 'checkNumber(this, \"int\")'";

			$phone = explode(' ', $input_value);

			//generates html
			echo "<label style='position: /*relative; top: -8px;*/'>
						".ucfirst($label).$required." </label>
                  <!-- <strong class='tel-plus'>+</strong> -->
                  <div class='telefonMum'>+ ";

            			$this->InputText($input_name.'_1', str_replace('+', '', $phone[0]), "id = '{$input_name}_1' class='tel-box1' maxlength = '3' onfocus='if(this.className==\"\") this.className=\"active\";' onblur='if(this.className==\"active\") this.className=\"\"; ValidatePhoneField(\"".LANG_NOT_BLANK."\"); ' onkeyup = 'if (this.value.length >= 3) ID(\"{$input_name}_2\").focus(); ' "." ".$align." ".$input_html_attributes.$js_validation.$validate_type);
            			$this->InputText($input_name.'_2', $phone[1], "id = '{$input_name}_2' class='tel-box2' maxlength = '3' onfocus='if(this.className==\"\") this.className=\"active\";' onblur='if(this.className==\"active\") this.className=\"\"; ValidatePhoneField(\"".LANG_NOT_BLANK."\"); ' onkeyup = 'if (this.value.length >= 3) ID(\"{$input_name}_3\").focus(); ' "." ".$align." ".$input_html_attributes.$js_validation.$validate_type);
            			$this->InputText($input_name.'_3', $phone[2], "id = '{$input_name}_3' class='tel-box3' style = 'width: 66px; float: none !important; ' onfocus='if(this.className==\"\") this.className=\"active\";' onblur='if(this.className==\"active\") this.className=\"\"; ValidatePhoneField(\"".LANG_NOT_BLANK."\"); '"." ".$align." ".$input_html_attributes.$js_validation.$validate_type);

				if (!empty($input_error))
				{
					echo "<span id = '{$input_name}_error' class='error'>$input_error<i></i></span>";
				}
				else
				{
					echo "<span id = '{$input_name}_error' class='error' style = 'display: none; '>$input_error<i></i></span>";
				}

            echo "<p class='tel-text'>".$comment."</p></div>";

			$this->InputErrorHandler($input_name, $input_error);
		}

		    /**
		 * Generates table row with radio group
		 *
		 * @param string $label label for the row
		 * @param string $input_name radio group name
		 * @param array $value_array array with the values for the radio group
		 * @param integer $selected selected value
		 * @param string $has_custom_field indicates whether radio group has custom variant (default: 0)
		 * @param string $input_html_attributes html_attributes for the input field
		 */
		public function RadioRowSite($label, $input_name, $value_array, $selected, $has_custom_field = 0, $input_html_attributes=null, $label_html_attributes=null)
		{
			global $current_controller, $object;

			$selected = ($selected == NULL) ? 0 : $selected;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $selected, &$input_html_attributes)) return;
			}

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];

			//generates html
			echo "<label $label_html_attributes >".ucfirst($label)."</label>
                  <div class='radioBatnTransfer'>";

			$this->RadioGroupSite($input_name, $value_array, $selected, $has_custom_field, "class='$this->checkboxCssClass' $input_html_attributes");

			echo "
                  </div>
                  <br class='clear' />
			";
		}

	    /**
		 * Generates a radio buttons group
		 *
		 * @param string $name radio group name
		 * @param array $assoc_array value array (value, text)
		 * @param string $checked_id indicates what field is checked (default: null)
		 * @param string $has_custom_field indicates whether radio group has custom variant (default: 0)
		 * @param string $htmlAttributes attributes for the tag (default: null)
	 	*/
		public function RadioGroupSite($name, $assoc_array, $checked_id = null, $has_custom_field, $html_attributes = null)
		{
			$was_checked = 0;
			foreach ($assoc_array as $v)
			{
				$value = array_shift($v);
				$text = array_shift($v);
				if ($value==$checked_id)
				{
					$checked=1;
					$was_checked=1;
				}
				else
				$checked = 0;

				if (strstr($text, "LANG_"))
				{
					eval ("\$text = ucfirst($text);");
				}

				if (!empty($checked)) $checked="checked = 'checked'";
				echo "
					<input type='radio' name='$name' value = '$value' id = '{$name}_{$value}' $checked onclick = 'if (this.value == 0) {document.getElementById(\"transfer_0\").style.display = \"\"; document.getElementById(\"transfer_1\").style.display = \"none\"; document.getElementById(\"transport_mean_id\").value = \"0\";} else {document.getElementById(\"transfer_1\").style.display = \"\"; document.getElementById(\"transfer_0\").style.display = \"none\"; document.getElementById(\"transport_mean_id\").value = \"1\";}' />
					<label for='$name' style='width: auto'>$text</label>
				";
			}
		}

		
	    /**
		 * Generates information table
		 * 
		 * @param string $text the text to display
  		 * @param integer $width table width
  		 * @param string $icon image
  		 * @param integer $icon_width image width
  		 * @param integer $icon_height image height
		*/		
		public function InformationTable($text, $width, $icon= null, $icon_width, $icon_height)
		{
			$this->DragNDropElement('informationtable');			
			echo "<table class='$this->informationalTableCssClass' cellspacing = 0 cellpadding = 0 border=0 width='".$width."'><tr>";
			if (!(empty($icon)))
			{
					echo "<td width = ".($icon_width+10).">";	
					$this->img($icon,$icon_width,$icon_height);
					echo "</td>";
			}
			echo "<td class = '$this->informationalTableCellCssClass'>";
			echo $text;
			echo "</td></tr></table></div>";
		}

	    /**
		 * Generates table for the mass operation
		 * 
		 * @param array $data text for output (default: LANG_NO_RECORDS)
		 * @param string $subject field name
		 * @param string $subject_id field id
		 * @param string $subject_label field label
  		 */			
		public function MassOperationTable($data, $subject, $subject_id, $subject_label)
		{
			global $current_controller;
			
			$this->form('');
			if (!isset($data[unaffected])) $data[unaffected]=0;
			echo "<div align='center'><table class='$this->massOperationsTableCssClass' width='60%'>";
			echo "<tr><td class = '$this->massOperationsHeaderCellCssClass' colspan='2'>".ucfirst(LANG_SELECTED_RECORDS)." (".LANG_UNAFFECTED.": ".$data[unaffected].")".":"."</td></tr>";
				
			//checks if we have smth to modify
			if (empty($data[$current_controller->name]))
			{
				echo "<tr><td colspan='2'>";
				$this->NoRecords();
				echo "</td></tr>";
			}	
			
			$i=0;
			foreach ($data[$current_controller->name] as $record)
			{
				if ($i%2==1) $rowStyle = $this->gridRowOddCssClass;
	    		else $rowStyle = $this->gridRowEvenCssClass;
				$cellStyle = $this->gridCellCssClass;				
				echo "<tr class = '$rowStyle'>".
						"<td class='$cellStyle' style='width: 100px; border-right-width: 1px; border-right-style: solid;'>$record[id]</td>".
						"<td class='$cellStyle' style='width: 100%'>{$record[$subject]}</td>".
				"</tr>";
				$this->hidden("ids[".$record[id]."]", $record[id]);
				$i++;				
			}
			echo "<tr><td class = '$this->massOperationsHeaderCellCssClass' colspan='2'>".ucfirst(LANG_CHANGE_TO).":"."</td></tr>";
			echo "<tr><td>".ucfirst($subject_label).":</td><td>";
			if (isset($data[records_list]))
				echo $this->combo($subject_id, $data[records_list], $claim[$subject_id], "class='$this->comboboxCssClass' style='width: 150px'");
			else
				echo $this->textarea($subject_id, '', '', "class='$this->comboboxCssClass' style='width: 150px'");
			
			echo "<tr><td colspan='2' align='center' style='border-top-width: 1px; border-top-style: solid; color: grey'>";
			$this->submitTable($this->submitButtonName, $current_controller->name);
			echo "</td></tr>";
			echo "</table></form>";
		}
		
	    /**
		 * Generates table for no records cases or errors
		 *
		 * @param text $text text for output (default: LANG_NO_RECORDS)
		 */			
		public function NoRecords($text = LANG_NO_RECORDS)
		{
			echo "<table width='100%'><tr><td width='100%' align='center'><span class = '$this->errorSpanCssClass'>".ucfirst($text)."</span></td></tr></table>";
		}
		
	    /**
		 * Generates header for the table
		 *
		 * @param string $text the text to display
  		 * @param integer $colspan number of columns to be joined
		*/		
		public function TableHeaderRow($text, $colspan = 3)
		{
		   	echo " 
		  	  <tr class='$this->tableHeaderRowCssClass'>
		  	  	<td class='$this->tableHeaderCellCssClass' colspan='$colspan'>".ucfirst($text)."</td>
		  	  </tr>";		 
		}
		
	    /**
		 * DEPRICATED: Generates the specified tag for the drag and drop operation
		 *
		 * @param string $id element id
		*/		
		public function DragNDropElement($id, $tag = 'div')
		{
//			global $object;
//			
//			if ($object->config->use_dragndrop)
//			{
//				$theme = $_SESSION[usertheme];
//				echo "<$tag {$_SESSION[dragndrop][$theme][$id]} id = '$id' class = 'dragme' style = 'position: relative;' onmouseup = 'dragndrop(this);'>";
//			}
		}

	    /**
		 * Generates title for the page
		 *
		 * @param string $text the text to display
		 * @param string $image image to display
		*/		
		public function MenuText1($text, $image, $url = '')
		{
			Logger::Debug('MenuText1 started');
			
			//url
			$url = (empty($url)) ? $_SERVER[REDIRECT_URL] : $url;
			
			//html
			echo "
				<table class = '$this->menuTextTableCssClass'>
					<tr>";
			
			            //image
            			if (!empty($image))
            			{
            				echo "<td width = '40'>";
            				    XHTML::Anchor($url, "<img src = '".IMAGES.SEPARATOR.$image."' width = '32' height = '32' alt = '$text' />");
            				echo "</td>";
            			}
            			
            echo "
            			<td class = '$this->menuTextCellCssClass'>".ucfirst($text)."</td>
            		</tr>
            	</table>";
			
			Logger::Debug('MenuText1 ended');
		}
		
		
		# FORM ROWS #
		
	    /**
		 * Generates tr (label) with the given text
		 *
		 * @param text $text text to be displayed
		 * @param string $input_html_attributes html_attributes for the td
		*/		
		public function LabelRow($text, $html_attributes = null)
		{
			echo "<tr><td ".$html_attributes.">".ucfirst($text)."</td></tr>";
		}
		
	    /**
		 * Generates td (label) with the given text
		 *
		 * @param text $text text to be displayed
		 * @param string $input_html_attributes html_attributes for the td
		*/		
		public function Label($text, $html_attributes = null)
		{
			echo "<td ".$html_attributes."> ".ucfirst($text)."</td>";
		}

	    /**
		 * Generates table row with the label and text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function LabelTextRow($label, $input_name, $input_value, $input_html_attributes=null, $check_permissions = 0, $tr_html_attributes='')
		{	
			global $current_controller, $object;
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
						
			//align depending on data type
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
				$align="style='text-align:right; padding-right:3px'";		
			else $align = "";
							
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label)."</td>
			    <td $align>
					$input_value
			    </td>
				<td>&nbsp;</td>
			  </tr>
			";			
		}
			
	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputTextRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{	
			global $current_controller, $object;
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
						
			//align depending on data type
			$align = $this->GetFieldStyle($current_controller, $input_name);
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $input_name, $input_html_attributes) ? "*" : "";
					
			//sets default value if needed
			$input_value = $this->GetFieldValue($current_controller, $input_name, $input_value);
					
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);
			
			//checks if min/max JS validaion is needed
			$validate_min_max = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][min_value]))
			{
				$min = $current_controller->controller_model->db_structure[$input_name][min_value];
				$validate_min_max = 1;
			}
			else $min = '-';
			
			if (isset($current_controller->controller_model->db_structure[$input_name][max_value]))
			{
				$max = $current_controller->controller_model->db_structure[$input_name][max_value];
				$validate_min_max = 1;
			}
			else $max = '-';

			//checks if regular expression validation is needed
			$validate_regexp = 0;
			if (isset($current_controller->controller_model->db_structure[$input_name][regexp_js]))
			{
				$regExp = $current_controller->controller_model->db_structure[$input_name][regexp_js];
				$validate_regexp = 1;
			}
			
			//combines JS validations
			$js_validation = '';
			if (($validate_min_max)||($validate_regexp))
			{
				if ($validate_min_max) $js_validation .= "ValidateMinMax(this, $min, $max); ";
				if ($validate_regexp) $js_validation .= "ValidateRegExp(this, /".$regExp."/, \"".ucfirst($label).': '.ucfirst(LANG_ATTENTION).'! '.ucfirst(LANG_NOT_REGEXP)."\")";
				$js_validation = " onChange = '$js_validation'";
			}
			
			//JS data type validation for the input value (according to the data type specified in the model)
			if (in_array($current_controller->controller_model->db_structure[$input_name][type], $current_controller->controller_model->data_engine->engine->database_formats[numeric_formats]))
			{	
				if ($current_controller->controller_model->db_structure[$input_name][type] == 'decimal') 
					$validate_type = " onKeyUp = 'checkNumber(this, \"float\")'";
				else
					$validate_type = " onKeyUp = 'checkNumber(this, \"int\")'";
			}

			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>
			    	<table cellpadding = '0' cellspacing = '0'>
			    		<tr>
			    			<td>";
								$this->InputText($input_name, $input_value, 'class="'.$this->inputTextCssClass.'"'." ".$align." ".$input_html_attributes.$js_validation.$validate_type);
								echo " 
							</td>
							<td style = 'padding-left: 5px;'> <span style='' class='$this->commentSpanCssClass'>$comment</span>
							</td>
						</tr>
					</table>
					";
					$this->InputLogComment($input_name);
					echo"
			    </td>
				<td class='$this->errorCellCssClass' width='150px'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  </tr>
			";
			
			$this->InputErrorHandler($input_name, $input_error);
		}

	    /**
		 * Generates table row with the input data field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputDateRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='', $jquery_settings = array())
		{	
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $input_name, $input_html_attributes) ? "*" : "";
					
			//sets default value if needed
			$input_value = $this->GetFieldValue($current_controller, $input_name, $input_value);
			
			//contracts time
			$input_value = substr($input_value, 0, 10);			
			
			if (!empty($input_value))
			{
				//date parts separator
				$date_parts_separator = (substr_count($input_value, '-', 0, strlen($input_value)) > 0 ) ? '-' : '.';
				
				$input_value_array = explode($date_parts_separator, $input_value);

				//swaps year and day if necessary
				if (strlen($input_value_array[0]) == 4)
				{
					$temp_swap = $input_value_array[0];
					$input_value_array[0] = $input_value_array[2];
					$input_value_array[2] = $temp_swap;
				}
				
				$input_value = implode($date_parts_separator, $input_value_array);
			}			
			
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);
			
			$input_value = (!empty($input_value)) ? date('d.m.Y', strtotime($input_value)) : '';
			$jquery_settings = array_merge($jquery_settings, array('changeYear' => true, 'changeMonth' => true, 'dateFormat' => '"dd.mm.yy"', 'yearRange' => '"-100:+100"', 'firstDay' => 1));
			jQuery::Datepicker($input_name, $jquery_settings);
			
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					$this->InputText($input_name, $input_value, 'class="'.$this->inputTextCssClass.'" style = "width: 150px; " readonly = "readonly" '." ".$align." id = '$input_name' ".$input_html_attributes.$js_validation.$validate_type);
			echo "
				</td>
			    <td class='$this->errorCellCssClass' width='150px'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  </tr>
			";
		}
		
	    /**
		 * Generates table row with the input datetime field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputDateTimeRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{	
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $input_name, $input_html_attributes) ? "*" : "";
					
			//sets default value if needed
			$input_value = $this->GetFieldValue($current_controller, $input_name, $input_value);
					
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);
			
			$temp = split(' ', $input_value);
			$input_value_array = split('-', $temp[0]);
			
			//swaps year and day if necessary
			if (strlen($input_value_array[0]) == 4)
			{
				$temp_swap = $input_value_array[0];
				$input_value_array[0] = $input_value_array[2];
				$input_value_array[2] = $temp_swap;
			}
			
			$time_value_string = $temp[1];
			
			$input_value = implode('-', $input_value_array);
			if (!empty($input_value)) $input_value .= ' '.$time_value_string;
			
			//translates months' array
			foreach (Arrays::$months as &$month)
			{
				eval("\$temp = {$month[name]};");
				$month[name] = $temp;
			}
						
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					
					//date
					echo LANG_DAY.': ';
					$this->inputText($input_name.'_day', $input_value_array[0], 'id="'.$input_name.'_day" onChange="ValidateMinMax(this, 0, 31); updateDate(\''.$input_name.'\');" style="width: 22px; height: 19px; text-align: right; padding-right: 3px; margin-right: 5px" class="'.$this->inputTextCssClass.'" maxlength="2" autocomplete = "off" '.$input_html_attributes);
					echo LANG_MONTH.': ';
					$this->combo($input_name.'_month', Arrays::$months, $input_value_array[1], 'id="'.$input_name.'_month" onChange="updateDate(\''.$input_name.'\');" style="text-align: left; width: 100px; margin-right: 5px" class="combobox" autocomplete = "off" '.$input_html_attributes);
					echo LANG_YEAR.': ';
					$this->inputText($input_name.'_year', $input_value_array[2], 'id="'.$input_name.'_year" onChange="updateDate(\''.$input_name.'\');" style="width: 38px; height: 19px; text-align: right; padding-right: 3px; margin-right: 5px" class="'.$this->inputTextCssClass.'" maxlength="4" autocomplete = "off" '.$input_html_attributes);
					
					//time
					$time_array = split(':', $time_value_string);
					echo '&nbsp;&nbsp;&nbsp;'.ucfirst(LANG_TIME).': ';
					$this->inputText($input_name.'_hour', $time_array[0], 'id="'.$input_name.'_hour" onChange="ValidateMinMax(this, 0, 23); updateDate(\''.$input_name.'\');" style="width: 22px; height: 19px; text-align: right; padding-right: 3px; " class="'.$this->inputTextCssClass.'" maxlength="2" autocomplete = "off" '.$input_html_attributes);
					echo ':';
					$this->inputText($input_name.'_minute', $time_array[1], 'id="'.$input_name.'_minute" onChange="ValidateMinMax(this, 0, 60); updateDate(\''.$input_name.'\');" style="width: 22px; height: 19px; text-align: right; padding-right: 3px; margin-right: 5px" class="'.$this->inputTextCssClass.'" maxlength="4" autocomplete = "off" '.$input_html_attributes);
					
					//comment
					echo " <span class='$this->commentSpanCssClass'>$comment</span>";
					
					$this->InputLogComment($input_name);
					
					$this->hidden($input_name, $input_value);
				echo "
				</td>
			    <td class='$this->errorCellCssClass' width='150px'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  
			   </tr>
			";			
		}

	    /**
		 * Generates table row with the input time field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param int $input_value input text field value which represents number of minutes since the beginning of the day
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputTimeRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{	
			global $current_controller, $object;

			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $input_name, $input_html_attributes) ? "*" : "";
					
			//sets default value if needed
			$input_value = $this->GetFieldValue($current_controller, $input_name, $input_value);
					
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);
			
			//calculates number of hours and minutes
			$hours = floor($input_value/60);
			$minutes = $input_value - $hours*60;
						
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					
					$this->inputText($input_name.'_hour', $hours, 'id="'.$input_name.'_hour" onChange="ValidateMinMax(this, 0, 23); updateTime(\''.$input_name.'\');" style="width: 22px; height: 19px; text-align: right; padding-right: 3px; " class="'.$this->inputTextCssClass.'" maxlength="2"'.$input_html_attributes);
					echo ':';
					$this->inputText($input_name.'_minute', $minutes, 'id="'.$input_name.'_minute" onChange="ValidateMinMax(this, 0, 60); updateTime(\''.$input_name.'\');" style="width: 22px; height: 19px; text-align: right; padding-right: 3px; margin-right: 5px" class="'.$this->inputTextCssClass.'" maxlength="4"'.$input_html_attributes);
					
					//comment
					echo " <span class='$this->commentSpanCssClass'>$comment</span>";
					
					$this->InputLogComment($input_name);
					
					$this->hidden($input_name, $input_value);
				echo "
				</td>
			    <td class='$this->errorCellCssClass' width='150px'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  
			   </tr>
			";			
		}
					
	    /**
		 * Generates table row with the combobox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox 
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param string $tr_html_attributes html attributes for the tr tag
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $comment comment
		 * @param string $parent_id_name field name of a parent ID
		*/		
		public function ComboBoxRow($label, $combo_name, $value_array, $selected = 0, $input_html_attributes=null, $tr_html_attributes=null, $check_permissions = 0, $comment = '', $parent_id_name = 'parent_id')
		{
			global $current_controller, $object;
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($combo_name, $selected, &$input_html_attributes)) return;	
			}			
						
			//for multi-level lists			
			if (isset($value_array[0][$parent_id_name])) $value_array = $this->GetMultiLevelList($value_array, $parent_id_name);

			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];

			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $combo_name, $input_html_attributes) ? "*" : "";
			
			//translates the array if needed
			if(!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			} 

			//checks whetther to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE) 
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}
			
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					$this->combo($combo_name, $value_array, $selected, "$input_html_attributes class='$this->comboboxCssClass'");
					echo " <span class='$this->commentSpanCssClass'>$comment</span>   
					";
					$this->InputLogComment($input_name);
					
					//for logs
					$pos = strpos($combo_name, '[');
					if($pos)
					$combo_name = substr($combo_name,0, $pos).'_text'.substr($combo_name,$pos);
					else
					$combo_name =$combo_name.'_text';
					$this->hidden($combo_name, '');
					
					echo"
					</td>
			    <td class='$this->errorCellCssClass' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";			
		}

	    /**
		 * gets multi-level list with indents from the given array (the array expects to have id, name, parent_id, which are hardcoded)
		 *
		 * @param array $list array to be sorted
		 * @param integer $parent_id id of the parent element
		*/
		public function GetMultiLevelList($list, $parent_id_name = 'parent_id')
		{
			//Logger::Debug("GetMultiLevelList started");
			$this->sortedCombo = array();
			$this->i = 0;
			
			//sorts the array for multi-level list
			Logger::Debug("MultiLevelSort started");
			$this->MultiLevelSort($list, 0, 0, 'id', 'name', $parent_id_name);
			Logger::Debug("MultiLevelSort ended");
			
			return $this->sortedCombo;
		}
		
	  /**
		 * sorts the array for multi-level list (recurse)
		 *
		 * @param array $elems label for the row
		 * @param integer $parent_id id of the parent element
		*/
		public function MultiLevelSort(&$elems, $parent_id = 0, $depth = 0, $id = 'id', $name = 'name', $parent_id_name = 'parent_id')
		{
			foreach ($elems as &$elem)
			{
				if ($elem[$parent_id_name] != $parent_id) continue;
				
				//adds spaces for for multi-level list element
				for ($k = 0; $k < $depth; $k++)
				{
					$elem[$name] = "&nbsp;&nbsp;&nbsp;".$elem[$name];
					$elem[depth]++;
				}
				
				$this->sortedCombo[$this->i] = $elem;
				
				$this->sorted_array[] = $elem[$id];
				
				$this->i++;
				$depth++;

				$this->MultiLevelSort($elems, $elem[$id], $depth, $id, $name);
				$depth--;
			}
			return $this->sortedCombo;
		}
		
	    /**
		 * Generates table row with the selectbox and additional input field for the quick filtering
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox 
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param string $tr_html_attributes html attributes for the row
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 */	
		public function SelectBoxFastSearchRow($label, $combo_name, $value_array, $selected, $input_html_attributes=null, $tr_html_attributes=null, $check_permissions = 0)
		{
			global $current_controller;
			
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];

			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $combo_name, $input_html_attributes) ? "*" : "";
			
			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}			
			
			echo "
			  <tr>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					$this->selectBoxFastSearch($combo_name, $value_array, $selected, $input_html_attributes, $tr_html_attributes, $check_permissions = 0);
				 echo "</td>
			    <td class='$this->errorCellCssClass' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";
				 
			$this->InputErrorHandler($combo_name, $input_error);	
		}
	
	    /**
		 * Generates the selectbox and additional input field for the quick filtering. Is used by SelectBoxFastSearchRow helper.
		 *
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox 
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param string $tr_html_attributes html attributes for the <nobr> element
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 */	
		public function SelectBoxFastSearch($combo_name, $value_array, $selected, $input_html_attributes=null, $tr_html_attributes = null, $check_permissions = 0)
		{
			global $current_controller, $object;
						
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($combo_name, $selected, &$input_html_attributes)) return;	
			}			
								
            if (isset($value_array[0][parent_id])) $value_array = $this->GetMultiLevelList($value_array);
            
			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}          
            
			//checks whether to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE) 
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}
			
			echo "<div $tr_html_attributes >";
					$this->select($combo_name, $value_array, $selected, "style='vertical-align: top;' class='$this->comboboxCssClass' id = '".$combo_name."' $input_html_attributes");
					echo "&nbsp;&nbsp;&nbsp;";
					$this->inputText('search_field', ' '.LANG_FAST_SEARCH.'...', "class='$this->inputTextSearchCssClass' id = 'search_field_".$combo_name."' style='width:120px' onClick='this.value=\"\"' onKeyUp='FastSearch(\"".$combo_name."\")'");    
					echo " <span class='$this->commentSpanCssClass'>$comment</span>";
					$this->InputLogComment($combo_name);
			echo"</div>";
		}
			
	    /**
		 * Generates table row with the selectbox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox 
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		*/		
		public function SelectBoxRow($label, $combo_name, $value_array = array(), $selected, $input_html_attributes=null, $check_permissions = 0)
		{
			global $current_controller, $object;
						
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($combo_name, $selected, &$input_html_attributes)) return;	
			}			
			
			if (isset($value_array[0][parent_id])) $value_array = $this->GetMultiLevelList($value_array);
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $combo_name, $input_html_attributes) ? "*" : "";
			
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$combo_name];
			
			//translates the array if needed
			if (!empty($value_array[0]))
			{
				foreach ($value_array[0] as $value)
				{
					if (strstr($value, 'LANG_'))
					{
						$value_array = $this->translateArray($value_array);
						break;
					}
				}
			}		
			
			//checks whetther to disable combo box
			if (strstr($input_html_attributes, "readonly") == TRUE) 
			{
				$input_html_attributes = $input_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			}			
			
			echo "
			  <tr>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					$this->select($combo_name, $value_array, $selected, "class='$this->comboboxCssClass' $input_html_attributes");
					echo " <span class='$this->commentSpanCssClass'>$comment</span>   
					";
					$this->InputLogComment($combo_name);
					echo"
				</td>
			    <td class='$this->errorCellCssClass' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";
			
			$this->InputErrorHandler($combo_name, $input_error);
		}
					
		/**
		 * Generate multiselect list box from binary tree
		 *
		 * @param string $label
		 * @param string $input_name
		 * @param array $value_array
		 * @param string $selected
		 * @param string $concat_field_id
		 * @param string $html_attributes
		 * @param string $tr_html_attributes
		 */				
		public function MultiListboxRow($label, $input_name, $value_array, $selected = '', $concat_field_id = '', $html_attributes = '', $tr_html_attributes = '', $hidden_field = '', $div_prefix='')
		{	
			Logger::Debug("MultiListboxRow ($input_name) started");		
			global $current_controller, $object;	
			
			$str = "<tr ".$tr_html_attributes."><td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td><td>";

			$str .= '<script type="text/javascript">
								var List = new Array();';
					
			trim($selected) == '' ? $str_js = " var hidden_val = '';" : $str_js = " var hidden_val = '".$selected."';";
			trim($concat_field_id) != '' ? $str_js .= " var id2fill = '".$concat_field_id."';" : $str_js .= " var id2fill = '';";
			$prev_key = -1;
			
			// array with parents
			$parents = array();
			
			$fullsize = count($value_array);
			
			// for page reload emulate click
			$edit = '';
									
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			
			// walk through input array
			foreach ($value_array as $key=> $value )
			{
				// list elements		
				foreach ( $value as $val_key => $val_val)
				{	
					if( $prev_key != $key)
						$str .= "List[".$key."] = new Array();";
					$str .= "List[".$key."]['".$val_key."'] = '".$val_val."';";				 			
					$prev_key = $key;
													
					if( trim($selected) != '' )
						if( $selected == $value[id] )
						{								
							// JS click emulation
							$edit = " show_child(".$value[id].",". $value[parent_id].", '".$input_name."', '".$concat_field_id."', '".$div_prefix."'); document.getElementById('".$hidden_field."').value = '".$div_prefix."'";						
						}						
					// fill array parents 	
					if( in_array($value[parent_id], $parents) == false )
						$parents[] = $value[parent_id];
				}				
								
			}
			
			$str .= "</script>";
			// count parent_id
			$size = count($parents);					
			
			// walk through parents		
			for( $i = 0; $i < $size; $i++ )
			{

				$display = 'none;';
				
				// show root only				
				if( $parents[$i] == 0 )
				{
					$display = 'block;';			
				}
										
					$str .= "<div style='float:left; display:".$display."' id='".$div_prefix."parent_".$parents[$i]."'><select size='4' id='select_".$div_prefix."parent_".$parents[$i]."' name='parent_".$parents[$i]."' class='$this->inputTextCssClass'  onchange=\"if(document.getElementById('".$hidden_field."') != null) document.getElementById('".$hidden_field."').value = '".$div_prefix."'; first_idx = this.options[this.selectedIndex].id.split('_'); second_idx = this.id.split('_'); arg1 = Number(first_idx[1]); arg2 = Number(second_idx[2]); moveElement(parentNode,'parent_'+arg1); show_child(arg1, arg2, '".$input_name."', '".$concat_field_id."', '".$hidden_field."', '".$div_prefix."'); \" ".$html_attributes.">";								
					
					for($k = $i; $k< $fullsize; $k++)
					{	 										
						if( $value_array[$k][parent_id] == $parents[$i] )
						{
														
							// generate output html	
							$str .= "<option id='opt_".$value_array[$k][id]."' value='".$value_array[$k][id]."' >".$value_array[$k][name]."</option>";
						}							
					}
					$str .="</select></div>";
			}
			$str .= "<input type='hidden' name='".$input_name."' id='".$input_name."' value=''><script type=\"text/javascript\">".$str_js." document.getElementById('".$input_name."').value = hidden_val; ".$edit."</script>";
						
			$str .= "</td>"	;
			// errors
			$str .= "<td width='150px'><span style='color: red'>$input_error</span></td></tr>";
			echo $str;
			Logger::Debug("MultiListboxRow ($input_name) ended"); 							
		}
			
	    /**
		 * Generates table row with the password input field
		 *
		 * @param string $label label for the row
		 * @param string $$input_name input field name
		 * @param string $input_value input field value 
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 */			
		public function PasswordRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0)
		{
			global $current_controller, $object;
						
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
						
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			
			echo "
			  <tr>
			    <td class='$this->labelCellCssClass'>".ucfirst($label)."*</td>
			    <td>";
					$this->password($input_name, $input_value, 'class="'.$this->inputTextCssClass.'"'." ".$input_html_attributes." ".$align);
					echo " <span class='$this->commentSpanCssClass'>$comment</span>   
					";
					$this->InputLogComment($input_name);
					echo"
				</td>
			    <td width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";			
			
			$this->InputErrorHandler($input_name, $input_error);
		}

	    /**
		 * Generates table rows with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputFilesRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{	
			global $current_controller, $object;
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $input_name, $input_html_attributes) ? "*" : "";
					
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);
			
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td id='inputFileTd'>";
			$this->inputFile($input_name.'[0]', $input_value, 'onChange="if (this.value) addInput(\'inputFileTd\');" class="'.$this->inputFileCssClass.'"'." ".$align." ".$input_html_attributes);
			echo " <span class='$this->commentSpanCssClass'>$comment</span>
			    </td>
			    <td class='$this->errorCellCssClass' width='150px'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  </tr>
			";			
		}

	    /**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputFileRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $tr_html_attributes='')
		{	
			global $current_controller, $object;
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $input_name, $input_html_attributes) ? "*" : "";
					
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			$id_span = str_replace('_','',$input_name);
			
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td id='inputFileTd'>";
			$this->inputFile($input_name, $input_value, 'class="'.$this->inputFileCssClass.'"'." ".$align." ".$input_html_attributes);
			$this->hidden('MAX_FILE_SIZE', $_SESSION[system_settings][file_max_upload_size]);
			echo " <span class='$this->commentSpanCssClass'>$comment</span>
			    </td>
			    <td class='$this->errorCellCssClass' width='150px'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  </tr>
			";			
		}
		
		/**
		 * Image upload row
		 * @param string $label
		 * @param string $name
		 * @param string $folder
		 * @param string $filename
		 * @param string $error
		 * @param string $html_attributes
		 */
		public function InputImageRow($label, $name, $folder, $filename, $error = '', $html_attributes = '')
		{
			?> 		
				<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $error; ?>">
				<input type="hidden" name="time_id" value="<?php echo time(); ?>">
				<input type="hidden" name="replace" value="y">
					<tr>
						<td class='label' style = ''><?php echo ucfirst($label); ?> </td>
						<td class=''>
						<?php if (strstr($html_attributes, "readonly") == FALSE) { ?>
							<input type="file" value = "" name="<?php echo $name;?>" id="<?php $name;?>" size="35" style="height: 21px;" class='<?php echo $this->inputTextCssClass; ?>'>
							<span class = 'error'><?php //echo $error; ?></span>
							<br />
						<?php } ?>
							<?php
								if (is_file($_SERVER['DOCUMENT_ROOT']."/app/upload/$folder/$filename"))
									$this->ToolTip("/app/upload/$folder/thumbs/$filename", "/app/upload/$folder/$filename");
								else
								{
									echo '-';
								}	
							?>
						</td>
					</tr>
			<?php 			
		}		
		
	    /**
		 * Generates table row with the checkbox input field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input field name
		 * @param boolean $is_checked indicates whether the element should be checked 
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $tr_html_attributes html attributes for the tr tag
		 * @param string $input_value checkbox value
	    */			
		public function CheckboxRow($label, $input_name, $is_checked, $input_html_attributes=null, $input_value=1, $tr_html_attributes='')
		{
			global $current_controller, $object;
						
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
					
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass' colspan='3'>";
					$this->hidden($input_name, '');
					$this->checkbox($input_name, $input_value, $is_checked, "class = '$checkboxCssClass' $input_html_attributes");
					echo " ".$label."\t  
					";
					$this->InputLogComment($input_name);
					echo"
				</td>
			  </tr>
			";			
		}		

		/**
		 * Generates checkbox group row
		 *
		 * @param string $label label
		 * @param string $input_name field name
		 * @param array $value_array array with all possible options
		 * @param array $selected_array array with selected options
		 */
		public function CheckBoxGroupRow($label, $input_name, array $value_array, $selected_array = array())
		{
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td>";
					foreach ($value_array as $item)
					{
						$id = array_shift($item);
						$text = array_shift($item);
						
						$checked = '';
						if (!empty($selected_array))
						{
							foreach ($selected_array as $k => $v)
							{
								if ($k == $id) $checked = "checked = 'checked'";
							}
						}
						
						echo "<nobr>";
						$this->CheckBox($input_name."[$id]", 1, $checked);
						echo $text."&nbsp;&nbsp;&nbsp;</nobr>";
					}
					
				echo "
				</td>
			    <td class='$this->errorCellCssClass' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";
		}		
		
		/**
		 * Generates checkbox group row for this project style
		 *
		 * @param string $label label
		 * @param string $input_name field name
		 * @param array $value_array array with all possible options
		 * @param array $selected_array array with selected options
		 */
		public function CheckBoxGroupRowPublic($label, $input_name, array $value_array, $selected_array = array())
		{
			//generates html
			echo ucfirst($label);
			echo "<br />";
					foreach ($value_array as $item)
					{
						$id = array_shift($item);
						$text = array_shift($item);
						
						$checked = '';
						if (!empty($selected_array))
						{
							foreach ($selected_array as $k => $v)
							{
								if ($k == $id) $checked = "checked = 'checked'";
							}
						}
						
						echo "<nobr>";
						$this->CheckBox($input_name."[$id]", 1, $checked);
						echo $text."&nbsp;&nbsp;&nbsp;</nobr>";
						echo "<br />";
					}

		}		
		
		/**
		 * Generates checkbox group row
		 *
		 * @param string $label label
		 * @param string $input_name field name
		 * @param array $value_array array with all possible options
		 * @param array $selected_array array with selected options
		 */
		public function CheckBoxMultiGroupTable($label, $input_name, array $value_arrays, $selected_array = array())
		{
			//generates html
			echo "
			<table class = 'eva'>";
			
			foreach ($value_arrays as $group => $value_array)
			{
				echo "
					<tr>
						<td class = '$this->tableHeaderCellCssClass'>$group</td>
					</tr>
					<tr $tr_html_attributes>
					  <td >";
							foreach ($value_array as $item)
							{
								$id = array_shift($item);
								$text = array_shift($item);
								
								$checked = '';
								if (!empty($selected_array))
								{
									foreach ($selected_array as $k => $v)
									{
										if ($k == $id) $checked = "checked = 'checked'";
									}
								}
								
								echo "<nobr>";
								$this->CheckBox($input_name."[$id]", 1, $checked);
								echo $text."&nbsp;&nbsp;&nbsp;</nobr>";
							}
							
					echo "
					   </td>
					</tr><tr><td><!-- --></td></tr>";
			}
			echo "	
			</table>
			";
		}		
		
	    /**
		 * Generates table row with radio group
		 *
		 * @param string $label label for the row
		 * @param string $input_name radio group name
		 * @param array $value_array array with the values for the radio group 
		 * @param integer $selected selected value
		 * @param string $has_custom_field indicates whether radio group has custom variant (default: 0)
		 * @param string $input_html_attributes html_attributes for the input field
		 */		
		public function RadioRow($label, $input_name, $value_array, $selected, $has_custom_field = 0, $input_html_attributes=null)
		{
			global $current_controller, $object;
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $selected, &$input_html_attributes)) return;	
			}			
						
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			
			//generates html
			echo "
			  <tr>
			    <td class='$this->labelCellCssClass'>".ucfirst($label)."</td>
			    <td>";
					$this->RadioGroup($input_name, $value_array, $selected, $has_custom_field, "class='$this->checkboxCssClass' $input_html_attributes");
					echo "\t   
					";
					$this->InputLogComment($input_name);
					echo"
				</td>
			    <td class='$this->errorCellCssClass' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";			
		}
		
		 /**
		 * Generates table row with radio group for this project style
		 *
		 * @param string $label label for the row
		 * @param string $input_name radio group name
		 * @param array $value_array array with the values for the radio group 
		 * @param integer $selected selected value
		 * @param string $has_custom_field indicates whether radio group has custom variant (default: 0)
		 * @param string $input_html_attributes html_attributes for the input field
		 */		
		public function RadioRowPublic($label, $input_name, $value_array, $selected, $has_custom_field = 0, $input_html_attributes=null)
		{
			global $current_controller, $object;
			
			//generates html
			echo "".ucfirst($label)."<br />";
					$this->RadioGroup($input_name, $value_array, $selected, $has_custom_field, "class='$this->checkboxCssClass' $input_html_attributes");
					echo "\t ";	
		}
		
	    /**
		 * Generates a radio buttons group
		 *
		 * @param string $name radio group name
		 * @param array $assoc_array value array (value, text)
		 * @param string $checked_id indicates what field is checked (default: null)
		 * @param string $has_custom_field indicates whether radio group has custom variant (default: 0)
		 * @param string $htmlAttributes attributes for the tag (default: null)
	 	*/
		public function RadioGroup($name, $assoc_array, $checked_id = null, $has_custom_field, $html_attributes = null)
		{
			$was_checked = 0;
			foreach ($assoc_array as $v)
			{
				$value = array_shift($v);
				$text = array_shift($v);
				if ($value==$checked_id)
				{
					$checked=1;
					$was_checked=1;
				}
				else 
				$checked = 0;
				
				if (strstr($text, "LANG_"))
				{
					eval ("\$text = ucfirst($text);");
				}
				
				$this->radio($name, $value, $text, $checked, $html_attributes);
				echo "<br />";
			}
			echo "<nobr>";
			if ($has_custom_field)
			{
				if (empty($was_checked)) 
				{
					$custom_value = $checked_id;
				}
				else $custom_value = '';
				$this->radio($name, $custom_value, LANG_OTHER_VARIANT.' ', $custom_value, "id = '".$name."_custom'".' '.$html_attributes);
				$this->inputText('', $custom_value, "id = '".$name."_custom_text' class='$this->inputTextCssClass' onChange='getElementById(\"".$name."_custom\").value=this.value;' onFocus='getElementById(\"".$name."_custom\").checked=true'".' '.$html_attributes);
			}
			echo "</nobr>";			
		}	
		
	    /**
		 * Generates table row with the textarea
		 *
		 * @param string $label label for the row
		 * @param string $textarea_name textarea name
		 * @param text $textarea_value textarea value
		 * @param string $input_html_attributes html_attributes for the textarea field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not
  		 * @param boolean $is_rich_textarea defines whether to use wysiwyg editor or not
		*/			
		public function TextareaRow($label, $textarea_name, $textarea_value, $input_html_attributes=null, $comment=null, $check_permissions = 0, $is_rich_textarea = null)
		{
			global $current_controller, $object;
			
			//if $is_rich_textarea is not specified, finds its value in the config variable
			if (!isset($is_rich_textarea)) 
			{
				if ($object->config->use_rta == 'true') $is_rich_textarea = 1;
				else $is_rich_textarea = 0;
			}
			
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($textarea_name, $input_html_attributes)) return;	
			}			
			
			//check whether to print '*' or not
			$required = $this->IsRequiredField($current_controller, $textarea_name, $input_html_attributes) ? "*" : "";
					
			//sets default value if needed
			$textarea_value = $this->GetFieldValue($current_controller, $textarea_name, $textarea_value);
			
			$input_error = $current_controller->controller_model->validation_errors[$textarea_name];
			$id_span = str_replace('_','', $textarea_name);
			
			echo "
			  <tr>
			    <td valign = 'top' class='$this->labelCellCssClass'>".ucfirst($label).$required."</td>
			    <td valign = 'top' style='vertical-align: top;'>";
				
				$this->Textarea($textarea_name, $textarea_value, $input_html_attributes, $is_rich_textarea);
				
				echo " <span class='$this->commentSpanCssClass'>$comment</span>
					";
					$this->InputLogComment($textarea_name);
					echo"
				</td>
			    <td class='$this->errorCellCssClass'><span id='".$id_span."error' style='color: red'>$input_error</span></td>
			  </tr>
			";		
			
			$this->InputErrorHandler($textarea_name, $input_error);
		}

	    /**
		 * Generates table row with the progress bar
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param boolean $check_permissions defines whether to check column permissions or not (default: 0)
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputProgressBarRow($label, $input_name, $input_value, $input_html_attributes = null, $comment = null, $check_permissions = 0, $tr_html_attributes = null)
		{
			//column permission check
			if (($object->config->use_column_permissions)&&(!$current_controller->ignore_columns_permissions)&&($check_permissions))
			{
				if (!$this->CheckColumnPermission($input_name, $input_value, &$input_html_attributes)) return;	
			}			
			
			echo '<tr '.$tr_html_attributes.'><td class = "'.$this->labelCellCssClass.'">'.ucfirst($label).'</td>';
			echo "<td><script>display('element1',".$input_value.",''); setValue('".$input_name."','element1');</script>";
			
			if (strstr($input_html_attributes, "readonly") == FALSE)
			{
				if($input_value != 100)
				{
					echo ' <span class="extra"><a href="#" onclick="emptyProgress(\'element1\');setValue(\''.$input_name.'\',\'element1\');return false;"><img src="'.IMAGES.'percent/icons/empty.gif" alt="'.LANG_CLEAR.'" title="'.LANG_CLEAR.'"/></a></span> ';
					echo '<span class="options"><a href="#" onclick="minus(\'element1\',\'5\');setValue(\''.$input_name.'\',\'element1\');return false;"><img src="'.IMAGES.'percent/icons/minus.gif" alt="'.LANG_DECREASE.'" title="'.LANG_DECREASE.'" /></a></span> ';
					echo '<span class="options"><a href="#" onclick="plus(\'element1\',\'5\');setValue(\''.$input_name.'\',\'element1\');return false;"><img src="'.IMAGES.'percent/icons/add.gif" alt="'.LANG_INCREASE.'" title="'.LANG_INCREASE.'"/></a></span> ';
					echo '<span class="options"><a href="#" onclick="setProgress(\'element1\',\''.$input_value.'\');return false;"><img src="'.IMAGES.'percent/icons/set.gif" alt="'.LANG_DEFAULT.'" title="'.LANG_DEFAULT.'" /></a></span> ';
					echo '<span class="options"><a href="#" onclick="fillProgress(\'element1\',\'100\');setValue(\''.$input_name.'\',\'element1\');return false;"><img src="'.IMAGES.'percent/icons/fill.gif" alt="'.LANG_FILL.'" title="'.LANG_FILL.'"  /></a></span> ';											
				}
			}			
			echo " <span class='$this->commentSpanCssClass'>$comment</span></td></tr>";
			$this->hidden($input_name, $input_value);			
		}		
		
	    /**
		 * Generates table row for no records cases or errors
		 *
		 * @param string $colspan number of columns to be joined 
		 * @param text $text text for output
		 */			
		public function NoRecordsRow($colspan, $text = LANG_NO_RECORDS)
		{
		   	echo " 
		  	  <tr>
		  	  	<td colspan='$colspan' class='$this->errorCellCssClass' align='center'>".ucfirst($text)."</td>
		  	  </tr>";		 
		}
		
		/**
		 * Generates table row with the inputbox and combobox
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox , default it is currencies
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * 
		*/		
		public function InputComboRow($label, $input_name, $input_value, $combo_name, $value_array='', $selected, $input_html_attributes=null, $combo_html_attributes=null)		
		{
			global $current_controller;
			if (empty($value_array))
				$value_array = $current_controller->GetModelObject('currencies')->ListItems(); 
				
			//check whether to print '*' or not 
			if (($current_controller->controller_model->db_structure[$input_name][not_null] == TRUE)&&(strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE)) 
			     $required = "*";   	
			else 
				 $required = "";
				 
			//checks whetther to disable combo box
			if (strstr($combo_html_attributes, "readonly") == TRUE) 
			{
				$combo_html_attributes = $combo_html_attributes." disabled = 'disabled'";
				$this->hidden($combo_name, $selected);
			} 
			
			//errors
			$input_error = $current_controller->controller_model->validation_errors[$input_name];
			
			//layout
			echo "<tr><td class='label'>".ucfirst($label).$required."</td><td><nobr>";
			$this->inputText($input_name, $input_value, 'class="text"'. " ".$input_html_attributes);
			echo '&nbsp;&nbsp;';
			$this->combo($combo_name, $value_array, $selected, $combo_html_attributes.' class="combobox" style="width:70px; height:17px;"');
			echo '</td><td class="error" width="150">
			<span id="levelerror" style="color: red;">'.$input_error.'</span>
			</td>';
			echo "</nobr></td></tr>";
			
			$this->InputErrorHandler($input_name, $input_error);
		}

		/**
		 * Multi-file upload table
		 * 
		 * @param $name
		 * @param $form_action
		 * @param $error
		 * @param $id
		 * @return unknown_type
		 */
		public function InputFilesTable($name, $error, $id = '')
		{
			echo " 		
				<input type='hidden' name='MAX_FILE_SIZE' value='$error'>
				<input type='hidden' name='time_id' value='".time()."'>
				<input type='hidden' name='replace' value='y'>
				<table cellpadding='1' cellspacing='1' class='eva'>
			";
			
			$this->TableHeaderRow(LANG_PHOTOS);
			
			for ($i = 0; $i < 5; $i++)
			{
				$input_name = $name.'_'.$i;
				
				echo "
					<tr>
						<td class='label'>".ucfirst(LANG_PHOTO)." #".($i+1)."</td>
						<td class=''><input type='file' value = '' name='$input_name' id='$input_name' size='35' style = '' class='$this->inputTextCssClass'></td>
						<td class = '$this->errorCellCssClass'>".$error[$input_name]."</td>
					</tr>
				";
			}
			
			echo "	
					<!--<tr>
						<td colspan='2' class='regError'>$error</td>
					</tr>-->
				</table>
			";		
		}		

		/**
		 * Generates table with images
		 *
		 * @param array $data images
		 * @param integer $columns number of columns
		 */
		public function GridImages($data, $folder, $readonly = false, $columns = '5', $options = array())
		{	
			global $current_controller;
			
			echo '
		    	<table class="gridImages" width="650" border="0" align="left" cellpadding="5" cellspacing="0">
		  	  		<tr class="header">
		  	  			<td class="header" colspan="'.$columns.'">'.ucfirst(LANG_UPOADED_PHOTOS).'</td>
		  	  		</tr>
		  	  		<tr>';

		       		$i=0; 
		       		foreach ($data as $image)
		       		{
		       			if ($i%$columns == 0) echo "</tr><tr>";
		       			
		       			echo "
		       				<td class='gridCell1' id = 'gridImagesCell$i'>
		       					<table align='center'>
		       						<tr>
		       							<td valign='top' class='' align = 'center'>
		       								<a href='' onClick='window.open(\"/".$current_controller->name."/viewImage/".$image[id]."\", \"_blank\", \"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes\")' >
						";
		       			
		       			$this->ToolTip("/app/upload/$folder/thumbs/$image[name]", "/app/upload/$folder/$image[name]"); 
		       			//<img src='/app/upload/$folder/thumbs/$image[name]' alt='".$image[description]."' title='".$image[description]."' class='grid' />
		       			
		       			echo "
		       								</a>
		       							</td>
		       						</tr>
		       						<tr>
		       							<td align='center'>";
		       			
		       			$name = str_replace('_', '+', $image[name]);
//		       			if (!$readonly) $this->link('/'.$current_controller->name.'/deleteImage/'.$image[id].'/'.$name.'/'.$folder, LANG_DELETE);
		       			if (!$readonly) $this->link("", LANG_DELETE, "onclick = 'if (confirm(\"Do you really want to delete this image?\")) {SendValues(\"/$current_controller->name/deletePhoto/$image[id]/$image[name]/?folder=$folder\"); document.getElementById(\"gridImagesCell$i\").style.display = \"none\";} return false; '");
		       			
		       			echo "
		       							</td>
		       						</tr>
		       						<tr>
		       							<td align = 'center'>";
											
		       								//image related data
							       			foreach ($options as $option)
							       			{
							       				switch ($option['type'])
							       				{
							       					case 'radio':
							       						$this->radio($option['name'], $image['id'], LANG_IS_DEFAULT, $image[$option['name']]);
							       						break;
							       					case 'text':
							       						echo '<br /><div style = "display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; width: 60px; text-align: right; ">'.$option['label'].'</div>';
							       						$this->InputText($option['name'].'['.$image['id'].']', $image[$option['name']], "class = '$this->inputTextCssClass' style = 'width: 150px; '");
							       						break;
							       					case 'combo':
							       						echo '<br /><div style = "display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; width: 60px; text-align: right; ">'.$option['label'].'</div>';
							       						$this->combo($option['name'].'['.$image['id'].']', $option['value_array'], $image[$option['name']], "class = '$this->comboboxCssClass' style = 'width: 150px; '");
							       						break;
							       					case 'select':
							       						echo '<br />';
							       						$this->select($option['name'].'['.$image['id'].']', $option['value_array'], $image[$option['name']], "class = '$this->comboboxCssClass' style = 'width: 150px; '");
							       						break;
							       				}
							       			}		       			
		       			
		       			echo "
		       							</td>
		       						</tr>
		       					</table>
		       				</td>";
		       			
		       			$i++;
		       		}
		       		
		     echo '</tr></table>';	
		}

		
		# FORM ELEMENTS #

	    /**
		 * Generates an input text field
		 *
		 * @param string $name input name
		 * @param string $value input value
		 * @param string $htmlAttributes attributes for the tag (default: null)
	 	*/		
		public function InputText($input_name, $input_value, $html_attributes = null)
		{
			global $current_controller;
			
			//sets default value 
			if (isset($current_controller->controller_model->db_structure[$input_name]['by_default'])&&(!isset($input_value)))
				$input_value = $current_controller->controller_model->db_structure[$input_name]['by_default'];
			
			//calls the parent function from html helper
			parent::InputText($input_name, $input_value, $html_attributes);
		} 
				
	    /**
		 * Generates a textarea tag
		 *
		 * @param string $name input name
		 * @param string $value input value
		 * @param string $htmlAttributes attributes for the tag (default: null)
	 	*/		
		public function Textarea($name, $value, $html_attributes = null, $is_rich_textarea = null)
		{
			global $object;

			//if $is_rich_textarea is not specified, finds its value in the config variable
			if ($is_rich_textarea == null) 
			{
				if ($object->config->use_rta == 'true') $is_rich_textarea = 1;
				else $is_rich_textarea = 0;
			}

			//if RTA
			if ($is_rich_textarea)
			{
    			if ((strstr($html_attributes, "readonly") == FALSE) && (strstr($html_attributes, "disabled") == FALSE)) $show_toolbars = 1;
    			else $show_toolbars = 0;
    			
    			parent::Textarea($name, $value, $html_attributes." id = {$name}_wysiwyg");
    			$this->JavaScript("WYSIWYG.attach('{$name}_wysiwyg');");
			}
			else
			{
				parent::Textarea($name, $value, $html_attributes);
			}
		} 
		
	    /**
		 * Generates a link
		 *
		 * @param string $url url
		 * @param string $text text
		 * @param string $htmlAttributes attributes for the tag (default: null)
		 * @param string $alt_text alternative text for the link (default: null)
		*/		
		public function Link($url, $text, $htmlAttributes = null, $alt_text = null)
		{
			//displays alternative text. Needs *TOOLTIP* section in CSS class
			if (isset($alt_text)) 
			{
				$text = $text.'<span class="tooltip"><span class="top"></span><span class="middle">'.$alt_text.'</span><span class="bottom"></span></span>';
				$htmlAttributes = $htmlAttributes." class='tt'";
			}
			parent::link($url, $text, $htmlAttributes);
		}
		
		
		# COMMON ELEMENTS AND FUNCTIONS #

	    /**
		 * Generates table with submit and cancel buttons
		 *
		 * @param string $sumbit_name submit button name
		 * @param string $cancel_url url for the redirection when the cancel button is pressed
		 */			
		public function SubmitTable($sumbit_name, $cancel_url, $show_cancel = true)
		{
			echo "
			  <table class = '$this->submitTableCssClass' border='0' cellspacing='0' cellpadding='1'>
			       <tr>
			       <td></td>
			            <td class = '$this->submitCellCssClass'>";
			$this->submit($sumbit_name, LANG_SUBMIT, "class = $this->submitButtonCssClass");
		    echo "          
		            </td>";
		    if ($show_cancel)
		    {
			    echo "
			            <td class = '$this->submitCellCssClass'>";
			    
		    	if (strstr($cancel_url, 'http://')) $this->cancel($cancel_url, LANG_CANCEL, "class = $this->cancelButtonCssClass");
			    else $this->cancel('/'.$cancel_url, LANG_CANCEL, "class = $this->cancelButtonCssClass");
			    
			    echo "</td>";
		    }
		    
			echo "
		        </tr>
		     </table>
		    "; 
		}

	    /**
		 * Checks permissions for the given input field
		 *
		 * @param string $input_name input field name
		 * @param string $input_html_attributes html_attributes for the input field
		*/		
		public function CheckColumnPermission($input_name, $input_value, &$input_html_attributes)
		{
			global $current_controller, $object;
			
			if (empty($current_controller->general[columns][$input_name][edit]))
			{
				if (empty($current_controller->general[columns][$input_name][view]))
				{
					$this->hidden($input_name, $input_value);
					return false;
				}
				else
				{
					$this->hidden($input_name, $input_value);
					$input_html_attributes = $input_html_attributes.' disabled="disabled"';
					return true;
				}
			}
			else 
			{
				return true;			
			}
		}
		
	    /**
		 * Generates table for deleting the record
		 *
		 * @param integer $id record id
		 */			
		public function ConfirmDeleteTable($id, $action='')
		{
			global $current_controller;
			global $object;
			
			//to see what you want to delete
			$view = str_replace('delete', 'view', $object->parsed_url[action]);
			
			HtmlHelper::tableOpen('align="center" class="'.$this->confirmDeleteTableCssClass.'"');
				HtmlHelper::trOpen();
					HtmlHelper::td(ucfirst(LANG_DO_YOU_REALLY_WANT_TO_DELETE_RECORD." <a href = '/{$current_controller->name}/$view/$id' target = '_blank'>".$id.'</a>?'), "colspan='2' align='center'");
				HtmlHelper::trClose();
				
				HtmlHelper::trOpen();
					HtmlHelper::tdOpen('align="right"');
						HtmlHelper::link('/'.$current_controller->name.'/'.$object->parsed_url[action].'/'.$id.'/1', strtoupper(LANG_YES));
					HtmlHelper::tdClose();
					HtmlHelper::tdOpen('align="left"');
						HtmlHelper::link($_SERVER[HTTP_REFERER], strtoupper(LANG_NO));
					HtmlHelper::tdClose();
					HtmlHelper::trClose();
			HtmlHelper::tableClose();			
		}
		
	    /**
		 * Generates input field, user in log commentation
		 *
		 * @param string $name field name
		 */			
		public function InputLogComment($name)
		{
			global $object, $current_controller;

			if (($object->config->use_logging_commentation)&&($object->config->use_logging)&&($current_controller->general[log_comments][$name]))
			{
				$this->inputText('logcomment_'.$name, LANG_ENTER_COMMENT_HERE.'...', 'class="'.$this->inputLogCommentCssClass.'" onClick="this.value=\'\'" onBlur="if(this.value==\'\') this.value=\''.LANG_ENTER_COMMENT_HERE.'...\'"');
			}
		}
		
	    /**
		 * Translates an array from LANG_ constants
		 *
		 * @param array $value_array array with the values
		 */			
		public function TranslateArray(array $value_array, $preserveOrder = false)
		{
			foreach ($value_array as &$value)
			{
				foreach ($value as &$val)
				{
					if (strstr($val, "LANG_"))
					{
						eval ("\$val = ucfirst($val);");
					}
				}				
			}
			unset($value);
			
			if (!$preserveOrder)
			{
				//sorts array according to its elements' translations
				foreach($value_array as $sortarray)
				{
					$column[] = $sortarray[name];
					if (($column[0] == NULL) || (sizeof($column) != sizeof($value_array)))
					{
						array_multisort($value_array, SORT_ASC);
					}
					else
					{
						array_multisort($column, SORT_ASC, $value_array, SORT_ASC);
					}
				}
			}

			return $value_array;
		}
				
		/**
		 * Handles the error in the input field
		 * 
		 * @param $input_name input field name
		 * @param $input_error input error
		 * @return
		 */
		public function InputErrorHandler($input_name, $input_error)
		{
			//mark the input field if there is an error
			if (!empty($input_error))
			{
				$this->JavaScript("temp = document.getElementsByName('$input_name'); temp[0].style.borderColor = 'red';");
			}
			else
			{

			}
		}
		

		#PRIVATE FUNCTIONALITY#
		
		/**
		 * Checks if the field is required
		 * @param object $current_controller
		 * @param string $input_name
		 * @param string $input_html_attributes
		 */
		private function IsRequiredField($current_controller, $input_name, $input_html_attributes)
		{
		    return (($current_controller->controller_model->db_structure[$input_name]['not_null'] == TRUE) && (strstr($input_html_attributes, "readonly") == FALSE) && (strstr($input_html_attributes, "disabled") == FALSE));
		}
		
		/**
		 * Gets fiels style
		 * @param object $current_controller
		 * @param string $input_name
		 */
		private function GetFieldStyle($current_controller, $input_name)
		{
		    return (in_array($current_controller->controller_model->db_structure[$input_name]['type'], $current_controller->controller_model->data_engine->engine->database_formats['numeric_formats'])) ? "style = 'text-align: right; padding-right: 3px '" : "";
		}
		
		/**
		 * Gets field value depending on 'by_default' value
		 * @param object $current_controller
		 * @param string $input_name
		 * @param string $input_value
		 */
		private function GetFieldValue($current_controller, $input_name, $input_value)
		{
		    return (isset($current_controller->controller_model->db_structure[$input_name]['by_default']) && (!isset($input_value))) ? $current_controller->controller_model->db_structure[$input_name]['by_default'] : $input_value;
		}
		
		
		# FEATURES #
		
		/**
		 * Generates table-bar with the given state
		 * @param $state integer current state
		 */
		function StatusBar($state)
		{
			echo "<table class='$this->statusBarTableCssClass' cellpadding='0' cellspacing='0'><tr>";
				echo "<td><b>0%&nbsp;</b></td>";
				echo "<td align='center' class='$this->statusBarTrueCellCssClass' style='width: ".$state."%'; ><nobr>$state%</nobr></td>";
				echo "<td style='width: ".(100-$state)."%'; class='$this->statusBarFalseCellCssClass'></td>";
				echo "<td><b>&nbsp;100%</b></td>";
			echo "</tr></table>";
		}

			/**
		 * Generates images' tooltip with
		 * 
		 * @param $thumbnail path to thumbnail image
		 * @param $image path to image
		 * @param $text popup text (optional)
		 */
		function ToolTip($thumbnail, $image, $text = '')
		{
			$this->Link("#thumb", "<img src='$thumbnail' border='0' />
			<span><img src='$image' /><br />$text</span>", "class='thumbnail'");
		}		
	}
?>